﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wwtfly.Utility;
using Wwtfly.BBS.Framework;
using Wwtfly.BBS.Framework.Caches;
using System.Data;
using System.Web.UI.HtmlControls;
using Wwtfly.BBS.BackBLL.Plays;
namespace Wwtfly.BBS.ForeApplication.WebForm
{
    public partial class LotterySSQ_ZHFB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridViewBind();
            }

        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridHeader));
            }

            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridHeader));
            }
        }

        protected void DrawGridHeader(HtmlTextWriter output, Control ctl)
        {
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#E8F1F8'>期号</td>");
            output.Write("<td colspan='33' align='center' valign='middle' bgcolor='#E8F1F8' height='18px'>红码走势</td>");
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#E8F1F8'>蓝码</td>");
      
            output.Write("<td rowspan='3'　align='center' valign='middle' bgcolor='#E8F1F8'>012路</td>");
            output.Write("<td colspan='5'　align='center' valign='middle' bgcolor='#E8F1F8'>红球号码分析</td>");

            output.Write("<tr align='center' valign='middle' bgcolor='#E8F1F8' height='18px'>");
            output.Write("<td colspan='11'>一区</td>");
            output.Write("<td colspan='11'>二区</td>");
            output.Write("<td colspan='11'>三区</td>");
            output.Write("<td rowspan='2'>重号</td>");
            output.Write("<td rowspan='2'>连号</td>");
            output.Write("<td rowspan='2'>总和</td>");
            output.Write("<td rowspan='2'>三区比</td>");
            output.Write("<td rowspan='2'>奇偶比</td>");
            output.Write("<tr align='center' valign='middle' bgcolor='#E8F1F8'>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px'>");
                output.Write(0 + i.ToString() + "</td>");
            }
            for (int i = 10; i < 34; i++)
            {
                output.Write("<td bgcolor='#f7f7f7'>");
                output.Write(i.ToString() + "</td>");
            }
        }

        protected void DrawGridFooter(HtmlTextWriter output, Control ctl)
        {
            output.Write("<td bgcolor='#f7f7f7' height='18px'>预选1</td>");

            for (int i = 1; i < 34; i++)
            {
                output.Write("<td onClick=Style(this,'../Images/red_" + i + ".gif') style='cursor:pointer' >&nbsp;</td>");
            }

            for (int i = 1; i < 8; i++)
            {
                output.Write("<td>&nbsp;</td>");
            }

            output.Write("<tr  >");
            output.Write("<td  bgcolor='#f7f7f7' height='18px'>预选2</td>");

            for (int i = 1; i < 34; i++)
            {
                output.Write("<td onClick=Style(this,'../Images/red_" + i + ".gif') style='cursor:pointer' >&nbsp;</td>");
            }

            for (int i = 1; i < 8; i++)
            {
                output.Write("<td>&nbsp;</td>");
            }

            output.Write("<tr  >");
            output.Write("<td  bgcolor='#f7f7f7' height='18px'>预选3</td>");

            for (int i = 1; i < 34; i++)
            {
                output.Write("<td onClick=Style(this,'../Images/red_" + i + ".gif') style='cursor:pointer' >&nbsp;</td>");
            }
            for (int i = 1; i < 8; i++)
            {
                output.Write("<td>&nbsp;</td>");
            }

            output.Write("<tr  bgcolor='#E8F1F8'>");
            output.Write("<td rowspan='3' >期号</td>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px' align='center'>");
                output.Write(0 + i.ToString() + "</td>");
            }
            for (int i = 10; i < 34; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' align='center'>");
                output.Write(i.ToString() + "</td>");
            }

            output.Write("<td rowspan='3' bgcolor='#E8F1F8'　>蓝码</td>");

            output.Write("<td rowspan='3'   >012路</td>");

            output.Write("<td rowspan='2'  >重号</td>");
            output.Write("<td rowspan='2'  >连号</td>");
            output.Write("<td rowspan='2'  >总和</td>");
            output.Write("<td rowspan='2'  >三区比</td>");
            output.Write("<td rowspan='2'  >奇偶比</td>");

            output.Write("<tr  bgcolor='#E8F1F8' height='18px'>");
            output.Write("<td colspan='11' >一区</td>");
            output.Write("<td colspan='11' >二区</td>");
            output.Write("<td colspan='11' >三区</td>");

            output.Write("<tr  bgcolor='#E8F1F8'>");
            output.Write("<td colspan='33'   height='18px'>红码走势</td>");
            output.Write("<td colspan='5'　>红球号码分析</td>");
        }
        protected void GridViewBind()
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(30, "", ""); //，默认显示30期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息！;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        public DataTable SSQ_DX_Select(int num, string str1, string str2)
        {
            DataTable dt = null;
            DataTable dt1 = null;

            dt = CacheHelper.Get("SSQ_ZHFB_Select") as DataTable;

            if (dt == null || dt.Rows.Count < 1)
            {
                dt = PlaysBLL.SelectSSQZHFBListWinber();
                CacheHelper.Insert("SSQ_ZHFB_Select", dt);
            }

            dt1 = dt.Clone();

            //通过期号来查询
            if (num == 0)
            {
                int i = str1.AsInt(0);
                int j = str2.AsInt(0);

                DataRow[] dr2 = dt.Select("Isuse>=" + i + " and  Isuse<=" + j);

                foreach (DataRow r in dr2)
                {
                    dt1.Rows.Add(r.ItemArray);
                }
            }

            //通过按纽选择查询多少期
            else
            {
                if (num >= dt.Rows.Count)
                {
                    num = dt.Rows.Count;
                }

                int ii = dt.Rows.Count;                           //总记录数
                int jj = ii - num;

                DataRow[] drr = dt.Select("id > " + jj + " and id <= " + ii);

                foreach (DataRow rr in drr)
                {
                    dt1.Rows.Add(rr.ItemArray);
                }
            }

            return dt1;
        }
        //搜索
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (tb1.Text == "" || tb1.Text == null || tb2.Text == "" || tb2.Text == null)
            {
                Response.Write("<script> alert('请输入起止期数！');</script>");
            }

            int i = tb1.Text.AsInt(0);
            int j = tb2.Text.AsInt(0);
            if (i > j)
            {
                Response.Write("<script> alert('起始期数输入有误，请查证在输入！');</script>");
                return;
            }

            DataTable dt = null;

            dt = SSQ_DX_Select(0, tb1.Text.ToString(), tb2.Text.ToString());

            if (dt == null || dt.Rows.Count < 1)
            {
                Response.Write("<script> alert('数据库里没有此彩种开奖号码信息！');</script>");
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示30
        protected void Button2_Click(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(30, "", ""); //，默认显示30期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示50
        protected void Button3_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(50, "", ""); //，默认显示50期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }
        //显示100
        protected void Button4_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = SSQ_DX_Select(100, "", ""); //，默认显示100期

            if (dt == null || dt.Rows.Count < 1)
            {
                //数据库里没有此彩种开奖号码信息!;
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }

        protected void ColorBind()
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                for (int j = 1; j < 34; j++)
                {
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(0) == 0)
                    {
                        HtmlImage img = new HtmlImage();
                        img.Src = "images/Qimg/red_" + j.ToString() + ".gif";

                        GridView1.Rows[i].Cells[j].Controls.Add(img);
                    }
                }

                if (GridView1.Rows[i].Cells[34].Text.AsInt(0) < 16)
                {
                    int k = GridView1.Rows[i].Cells[34].Text.AsInt(0);

                    HtmlImage img = new HtmlImage();
                    img.Src = "images/Qimg/blue_" + k.ToString() + ".gif";

                    GridView1.Rows[i].Cells[34].Controls.Add(img);
                }
            }
        }
    }
}